package com.haierp.service.bi.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.haierp.mapper.bi.BiSaleMapper;
import com.haierp.mapperBi.BiPurchaseStorageLaMapper;
import com.haierp.mapperBi.BiReturnReasonMapper;
import com.haierp.mapperBi.BiSaleSizeQuantityMapper;
import com.haierp.mapperBi.BiSalesVolumeDayMapper;
import com.haierp.model.bi.BiPurchaseStorageLa;
import com.haierp.model.bi.BiReturnReason;
import com.haierp.model.bi.BiSale;
import com.haierp.model.bi.BiSaleSizeQuantity;
import com.haierp.model.bi.BiSaleSkuMonth;
import com.haierp.model.bi.BiSalesVolumeDay;
import com.haierp.service.bi.IBiSaleService;
import com.haierp.util.DateUtil;

@Service("biSaleService")
public class BiSaleServiceImpl extends SuperServiceImpl<BiSaleMapper, BiSale>  implements IBiSaleService {
	@Autowired
	private BiSaleMapper biSaleMapper;
	@Autowired
	private BiSalesVolumeDayMapper biSalesVolumeDayMapper;
	@Autowired
	private BiReturnReasonMapper biReturnReasonMapper;
	@Autowired
	private BiSaleSizeQuantityMapper biSaleSizeQuantityMapper;
	@Autowired
	private BiPurchaseStorageLaMapper biPurchaseStorageLaMapper;
	@Override
	public List<BiSalesVolumeDay> selectSaleReportByGmtCreate(Long companyId) {
		EntityWrapper<BiSalesVolumeDay> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.addFilter("dimension_date<{0}",DateUtil.formatSimpleDate(DateUtil.getDateLeft(new Date(), -6)));
		entityWrapper.orderBy("dimension_date", false);
		List<BiSalesVolumeDay> biSalesVolumeDayList = biSalesVolumeDayMapper.selectList(entityWrapper);
		List<BiSalesVolumeDay> saleReportList = biSaleMapper.selectSaleReportByGmtCreate(companyId);
		biSalesVolumeDayList.addAll(0, saleReportList);
		return biSalesVolumeDayList;
	}

	@Override
	public List<BiSalesVolumeDay> selectSaleReportByGmtCreateMouth(Long companyId) {
		List<BiSalesVolumeDay> saleReportMouthList = biSaleMapper.selectSaleReportByGmtCreateMouth(companyId);
		List<BiSalesVolumeDay> biSaleReportMouthList = biSalesVolumeDayMapper.biSelectSaleReportByGmtCreateMouth(companyId);
		biSaleReportMouthList.addAll(0, saleReportMouthList);
		return biSaleReportMouthList;
	}

	@Override
	public List<BiSale> selectSaleReportExcelByGmtCreate() {
		return biSaleMapper.selectSaleReportExcelByGmtCreate();
	}

	@Override
	public List<BiSale> selectSaleReportByCategoryName() {
		return biSaleMapper.selectSaleReportByCategoryName();
	}

	@Override
	public List<BiSale> selectSaleReportByBand() {
		return biSaleMapper.selectSaleReportByBand();
	}

	@Override
	public List<BiReturnReason> selectRefundReport(Long companyId) {
		EntityWrapper<BiReturnReason> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.orderBy("dimension_date", false);
		return biReturnReasonMapper.selectList(entityWrapper);
	}

	@Override
	public List<BiSaleSizeQuantity> selectSaleReportByScale(Long companyId) {
		EntityWrapper<BiSaleSizeQuantity> entityWrapper = new EntityWrapper<>();
		entityWrapper.where("company_id={0}", companyId);
		entityWrapper.orderBy("sale_total_num", false);
		return biSaleSizeQuantityMapper.selectList(entityWrapper);
	}

	@Override
	public List<BiSale> selectSaleItemReportByHistory(Long companyId) {
		return biSaleMapper.selectSaleItemReportByHistory(companyId);
	}

	@Override
	public List<BiSaleSkuMonth> selectSaleItemReportByMouth(BiSaleSkuMonth biSaleSkuMonth) {
		return biSaleMapper.selectSaleItemReportByMouth(biSaleSkuMonth);
	}

	@Override
	public BiSale selectSaleItemReportByProbability(Long companyId) {
		return biSaleMapper.selectSaleItemReportByProbability(companyId);
	}

	@Override
	public List<BiSale> countMistakeMan() {
		return biSaleMapper.countMistakeMan();
	}

	@Override
	public List<BiPurchaseStorageLa> countStephPuchaseQuantity() {
		EntityWrapper<BiPurchaseStorageLa> entityWrapper = new EntityWrapper<>();
		entityWrapper.orderBy("dimension_date", false);
		return biPurchaseStorageLaMapper.selectList(entityWrapper);
	}

	@Override
	public List<BiSale> selectAllPurchaserQuantity() {
		return biSaleMapper.selectAllPurchaserQuantity();
	}

	@Override
	public List<BiSale> purchasePerformance() {
		return biSaleMapper.purchasePerformance();
	}
}
